<template>
  <div class="header admin-header-fixed">
    <h1 class="page-title">{{ title }}</h1>
    <el-dropdown class="admin-dropdown" trigger="hover" @command="handleCommand">
      <div class="user-info">
        <div class="user-avatar">{{ user.avatar }}</div>
        <div class="user-name">{{ user.name }}</div>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item command="profile">个人中心</el-dropdown-item>
          <el-dropdown-item command="settings">设置</el-dropdown-item>
          <el-dropdown-item divided command="logout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
import { useAppStore } from '@/stores/appStore'
export default defineComponent({
  name: 'AdminHeader',
  props: {
    title: { type: String, required: true },
    user: { type: Object, required: true }
  },
  setup(props) {
    const router = useRouter()
    const appStore = useAppStore()
    function handleCommand(cmd: string) {
      if (cmd === 'profile') {
        ElMessage.info('个人中心功能待实现')
      } else if (cmd === 'settings') {
        ElMessage.info('设置功能待实现')
      } else if (cmd === 'logout') {
        appStore.logout()
        ElMessage.success('已退出登录')
        router.push('/admin/login')
      }
    }
    return { ...props, handleCommand }
  }
})
</script>
<style scoped>
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
  margin-bottom: 20px;
  border-bottom: 1px solid #e9ecef;
}
.admin-header-fixed {
  position: fixed;
  top: 0;
  left: 260px;
  right: 0;
  z-index: 101;
  background: #fff;
  height: 70px;
  padding: 0 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  border-bottom: 1px solid #e9ecef;
  display: flex;
  align-items: center;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}
.mode-toggle {
  color: #0d6efd;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  transition: color 0.3s;
}
.mode-toggle:hover {
  color: #232946;
}
.page-title {
  font-size: 24px;
  font-weight: 700;
  color: #0d1b2a;
}
.admin-dropdown {
  display: inline-block;
  width: fit-content;
  min-width: 180px;
}
.user-info {
  width: fit-content;
  min-width: 180px;
  padding: 0 16px;
  height: 48px;
  border-radius: 24px;
  background: #f6faff;
  box-shadow: 0 1px 4px rgba(13,110,253,0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
  transition: background 0.2s;
}
.user-info:hover {
  background: #e6f0ff;
}
.user-info:focus-visible .user-info:focus{
  border: none;
}
.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0d6efd, #0dcaf0);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 18px;
}
.user-name {
  font-weight: 500;
  color: #212529;
  font-size: 16px;
}
</style> 